package com.coding.kan_yi_dao.service.impl;

import com.coding.kan_yi_dao.common.Result;
import com.coding.kan_yi_dao.entity.Carousel;
import com.coding.kan_yi_dao.entity.GoodsNew;
import com.coding.kan_yi_dao.mapper.CarouselMapper;
import com.coding.kan_yi_dao.service.ICarouselService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 砍一刀，不买就砍你一刀
 * @since 2023-09-20
 */
@Service
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper, Carousel> implements ICarouselService {
    //全查询
    @Override
    public Result go_select_carousel() {
        List<Carousel> a = baseMapper.selectList(null);
        return Result.ok(a);
    }

    //添加
    @Override
    public Result go_insert(Carousel carousel) {
        return Result.ok(baseMapper.insert(carousel));
    }

    //删除
    @Override
    public Result go_delete(List<Integer> ids) {
        List<Carousel> carousels = new ArrayList<>();
        for (int i = 0; i < ids.size(); i++) {
            Carousel carousel = new Carousel();
            carousel.setCarouselId(ids.get(i));
            carousel.setIsDeleted(1);
            carousels.add(carousel);
        }
        /*System.out.println(goodsNewss);return Result.ok(this.update().setSql("goods_delete=0").in("goods_new_id",goodsNewss).update());*/
        return Result.ok(updateBatchById(carousels));
    }

    //修改
    @Override
    public Result go_update(Carousel carousel){
        Carousel carousel1 = new Carousel();
        carousel1.setCarouselId(carousel.getCarouselId());
        carousel1.setCarouselUrl(carousel.getCarouselUrl());
        carousel1.setRedirectUrl(carousel.getRedirectUrl());
        carousel1.setCarouselRank(carousel.getCarouselRank());
        return Result.ok(updateById(carousel1));
    }
}
